{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "import glob\n",
    "import numpy as np\n",
    "from shutil import copyfile\n",
    "symlink = True    # If this is false the files are copied instead\n",
    "combine_train_valid = False    # If this is true, the train and valid sets are ALSO combined"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# List Imagenet contributors\n",
    "\n",
    "This notebook serves to collate which imagenet contributions were randomly selected to add to CINIC. These can be traced back to [image-net.org](image-net.org) for redownload.\n",
    "\n",
    "#### ENSURE THAT CINIC-10 IS DOWNLOADED AND STORED IN ../data/cinic-10"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "cinic_directory = \"../data/cinic-10\"\n",
    "classes = [\"airplane\", \"automobile\", \"bird\", \"cat\", \"deer\", \"dog\", \"frog\", \"horse\", \"ship\", \"truck\"]\n",
    "sets = ['train', 'valid', 'test']\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "meta_information = {}\n",
    "\n",
    "for s in sets:\n",
    "    for c in classes:\n",
    "        source_directory = '{}/{}/{}'.format(cinic_directory, s, c)\n",
    "        filenames = glob.glob('{}/*.png'.format(source_directory))\n",
    "        for fn in filenames:\n",
    "            if 'cifar' not in fn.split('/')[-1]:\n",
    "                synset = fn.split('/')[-1].split('.')[0].split('_')[0]\n",
    "                imgno = int(fn.split('/')[-1].split('.')[0].split('_')[1])\n",
    "                meta_information[(synset, imgno)] = (s, c)                 "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "scrolled": false
   },
   "outputs": [],
   "source": [
    "with open('../imagenet-contributors.csv', 'w') as f:\n",
    "    f.write('synset, image_num, cinic_set, class\\n')\n",
    "    for (synset, imgno), (s, c) in meta_information.items():\n",
    "        f.write('{}, {}, {}, {}\\n'.format(synset, imgno, s, c))"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
